import { reqGetSearchGoodsInfoData } from "@/api"

const state = {
  goodsInfo: {},
  trademarkList: {}
}
const actions = {
  // 1. 根据参数 获取搜索数据
  async getSearchGoodsInfoData({commit},searchParams) {
    const result =await reqGetSearchGoodsInfoData(searchParams)
    // 判断是否成功
    console.log(result)
    if (result.code === 200) {
      commit('SAVE_GOODS_INFO_DATA',result.data)
    } else {
      console.log(result.message)
    }
  }
}
const mutations = {
  // 1. 存储搜索到的商品
  SAVE_GOODS_INFO_DATA(state, goodsInfo) {
    state.goodsInfo = goodsInfo
  }
}
const getters = {
  //1.属性列表
  attrsList(state) {
    return state.goodsInfo.attrsList
  },
  //2.商品列表
  goodsList(state) {
    return state.goodsInfo.goodsList
  },
  //3.商品品牌列表
  trademarkList(state) {
    return state.goodsInfo.trademarkList
  },
  // 总页数
  total(state) {
    return state.goodsInfo.total;
  }
}

export default {
  namespaced:true, // 开启命名空间 区分不同的模块
  state,
  actions,
  mutations,
  getters
}